#include "GameCommonInfo.h"
#include "Box.h"
#include "Level.h"
#include "Utils.h"

GameCommonInfo* GameCommonInfo::instance = 0;

GameCommonInfo::GameCommonInfo()
{
	curBox = 0;
	curLevel = 0;
	curBoxIndex = curLevelIndex = 0;
}

GameCommonInfo* GameCommonInfo::GetInstance()
{
	if(instance == 0)
	{
		PRINT("Init GameCommonInfo Instance\n");
		instance = new GameCommonInfo();
	}
	return instance;
}

void GameCommonInfo::SetCurLevel(int index)
{
	curLevelIndex = index;
	curLevel = curBox->GetLevel(index);
}
void GameCommonInfo::SetCurBox(int index)
{
	curBoxIndex = index;
	curBox = boxes[index];
}

void GameCommonInfo::NextLevel()
{
	int newCurLevelIndex = curLevelIndex + 1;
	if(newCurLevelIndex < curBox->GetLevels()->size())
		SetCurLevel(newCurLevelIndex);
	else NextBox();
}

void GameCommonInfo::NextBox()
{
	int newCurBoxIndex = curBoxIndex + 1;
	if(newCurBoxIndex < boxes.size())
		SetCurBox(newCurBoxIndex);
}

GameCommonInfo::~GameCommonInfo()
{

}

void GameCommonInfo::DestroyInstance()
{
	DELETE_SAFELY(instance);
}